home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Graphics / sKulpt / skulpt-src / Ami-Console.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-27  |  2.9 KB  |  121 lines

  1. #include <exec/io.h>
  2. #include <exec/memory.h>
  3. #include <exec/lists.h>
  4. #include <libraries/dos.h>
  5. #include <devices/console.h>
  6. #include <ctype.h>
  7. #include <clib/exec_protos.h>
  8. #include <clib/dos_protos.h>
  9. #include <clib/alib_protos.h>
  10. #include <intuition/intuition.h>
  11.  
  12. BYTE bConsoleOpened = FALSE;
  13.  
  14. static struct IOStdReq  *hWriteReq;
  15. static struct MsgPort   *hWritePort;
  16. static struct IOStdReq  *hReadReq;
  17. static struct MsgPort   *hReadPort;
  18.  
  19. #ifdef XDC_EXTENDED_CONSOLE
  20.  
  21. #define RESETCON    "\033c"
  22. #define CURSOFF        "\033[0 p"
  23. #define CURSON        "\033[p"
  24.  
  25. #define COLOR02        "\033[32m"
  26. #define COLOR03        "\033[33m"
  27. #define ITALICS        "\033[3m"
  28. #define BOLD        "\033[1m"
  29. #define UNDERLINE    "\033[4m"
  30. #define NORMAL        "\033[0m"
  31.  
  32. void ConPutChar(struct IOStdReq *hWriteReq, UBYTE character)
  33. {
  34.     if (!bConsoleOpened) return;
  35.  
  36.     hWriteReq -> io_Command = CMD_WRITE;
  37.     hWriteReq -> io_Data = (APTR) &character;
  38.     hWriteReq -> io_Length = 1;
  39.     DoIO((struct IORequest *) hWriteReq);
  40. }
  41.  
  42. void ConWrite(struct IOStdReq *hWriteReq, UBYTE string, LONG length)
  43.     if (!bConsoleOpened) return;
  44.  
  45.     hWriteReq -> io_Command = CMD_WRITE;
  46.     hWriteReq -> io_Data = (APTR) string;
  47.     hWriteReq -> io_Length = length;
  48.     DoIO((struct IORequest *) hWriteReq);
  49. }
  50. #endif
  51.  
  52. void ConPutS(char *str)
  53. {
  54.     if (!bConsoleOpened) return;
  55.  
  56.     hWriteReq -> io_Command = CMD_WRITE;
  57.     hWriteReq -> io_Data = (APTR) str;
  58.     hWriteReq -> io_Length = -1;
  59.     DoIO((struct IORequest *) hWriteReq);
  60. }
  61.  
  62. void CloseConsole(void)
  63. {
  64.     if (bConsoleOpened)
  65.     {
  66.         bConsoleOpened = FALSE;
  67.         CloseDevice((struct IORequest *) hWriteReq);
  68.     }
  69.  
  70.     if (hReadReq)
  71.     {
  72.         DeleteExtIO((struct IORequest *) hReadReq);
  73.         hReadReq = NULL;
  74.     }
  75.  
  76.     if (hReadPort)
  77.     {
  78.         DeletePort(hReadPort);
  79.         hReadPort = NULL;
  80.     }
  81.  
  82.     if (hWriteReq)
  83.     {
  84.         DeleteExtIO((struct IORequest *) hWriteReq);
  85.         hWriteReq = NULL;
  86.     }
  87.  
  88.     if (hWritePort)
  89.     {
  90.         DeletePort(hWritePort);
  91.         hWritePort = NULL;
  92.     }
  93. }
  94.  
  95. BOOL InitConsole(Window *hWnd)
  96.     // Create Reply Port and IOReq for writing
  97.     if (!(hWritePort = CreatePort("__console.write",NULL))) goto _InitFailed;
  98.     if (!(hWriteReq = (struct IOStdReq *) CreateExtIO(hWritePort, (LONG)sizeof(struct IOStdReq)))) goto _InitFailed;
  99.  
  100.     // Create Reply Port and IOReq for reading
  101.     if (!(hReadPort = CreatePort("__console.read",NULL))) goto _InitFailed;
  102.     if (!(hReadReq = (struct IOStdReq *) CreateExtIO(hReadPort, (LONG)sizeof(struct IOStdReq)))) goto _InitFailed;
  103.  
  104.     // Attach a console to the console window
  105.     hWriteReq -> io_Data = (APTR) hWnd;
  106.     hWriteReq -> io_Length = sizeof(struct Window);
  107.     
  108.     // Open console device
  109.     if (!(bConsoleOpened = (OpenDevice("console.device", 0, (struct IORequest *) hWriteReq,0) ? FALSE : TRUE))) goto _InitFailed;
  110.     hReadReq -> io_Device = hWriteReq -> io_Device;
  111.     hReadReq -> io_Unit = hWriteReq -> io_Unit;
  112.     return TRUE;
  113.  
  114. _InitFailed:
  115.     CloseConsole();
  116.     return FALSE;
  117. }
  118.  
  119.